/**
 * Lists all children of the node (defined with nodeRef or documentLibrary
 * relative path) that has the given aspect. Called as:
 * "alfresco/service/tr/gov/tubitak/bpms/findNodeWithAspect?parentNodeRef=workspace://SpacesStore/a3865712-a9b8-4037-98dc-056fbc7ec1ea&aspectNames=["epdk:eksikEvrakAspect"]"
 * or
 * "http://localhost:9090/alfresco/service/tr/gov/tubitak/bpms/findNodeWithAspect?parentFolder=/Daireler/DPDB/Şablonlar&site=epdk&aspectNames=["epdk:eksikEvrakAspect"]"
 */
function main() {
	if (args.parentNodeRef) {
		// call service with nodeRef param
		var parentNode = search.findNode(args.parentNodeRef);
	} else {
		var docLibNode = companyhome.childByNamePath("/Sites/" + args.site
				+ "/documentLibrary")
		if (args.parentFolder == "root") {
			var parentNode = docLibNode;
		} else {
			// call service with nodePath param
			var parentNode = docLibNode.childByNamePath(args.parentFolder);
		}
	}

	var childNodes = parentNode.children;

	var results = new Array();

	for ( var i = 0; i < childNodes.length; i++) {
		var searchedAspects = eval('(' + args.aspectNames + ')');
		var hasAllAspects = true;
		for ( var j = 0; j < searchedAspects.length; j++) {
			hasAllAspects = hasAllAspects
					& childNodes[i].hasAspect(searchedAspects[j])
		}
		if (hasAllAspects) {
			results.push(childNodes[i].nodeRef);
		}
	}

	// stringify root folder
	var jsonString = jsonUtils.toJSONString(results);
	model.jsonString = jsonString;
}

main();